package com.hotel.web.controller.hotel;

import com.hotel.common.core.controller.BaseController;
import com.hotel.common.core.domain.AjaxResult;
import com.hotel.common.core.page.TableDataInfo;
import com.hotel.system.domain.hotel.Room;
import com.hotel.system.domain.hotel.RoomType;
import com.hotel.system.service.ISysDeptService;
import com.hotel.system.service.RoomService;
import com.hotel.system.service.RoomService;
import com.hotel.system.service.RoomTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 酒店房间信息操作处理
 * 
 * @author hotel
 */
@Controller
@RequestMapping("/hotel/room")
public class RoomController extends BaseController
{
    private String prefix = "hotel/room/";

    @Autowired
    private RoomService roomService;
    @Autowired
    private RoomTypeService roomTypeService;

    @RequiresPermissions("hotel:room:view")
    @GetMapping()
    public String room()
    {

        return prefix + "room";
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Room room)
    {
//        SysDept dept = new SysDept();
//        dept.setDeptId(ShiroUtils.getSysUser().getDeptId());
//        List<SysDept> deptList = deptService.selectDeptList(dept);
//        System.out.println(deptList);

        startPage();
        List<Room> list = roomService.selectRoomList(room);
        return getDataTable(list);
    }

    @RequiresPermissions("hotel:room:add")
    @GetMapping("/add")
    public String addRoom(ModelMap mmap)
    {
        mmap.put("roomTypes", roomTypeService.selectRoomTypeAll());
        return prefix + "add";
    }

    @RequiresPermissions("hotel:room:add")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated Room room) {

        return toAjax( roomService.insertRoom(room));
    }

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("room", roomService.selectRoomId(id));
        mmap.put("roomTypes", roomTypeService.selectRoomTypeAll());
        return prefix + "edit";
    }

    /**
     * 出库入库调整
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editRoom(@Validated Room room)
    {
        return toAjax(roomService.updateRoom(room));
    }

    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(roomService.updateRoomStatus(ids));
    }


    /**
     * 校验房间类型名称唯一
     * @param room
     * @return
     */
    @PostMapping("/checkRoomNameUnique")
    @ResponseBody
    public boolean checkRoomNameUnique(Room room)
    {
        return roomService.checkRoomNameUnique(room);
    }




}
